import {
    SET_FULL_SCREEN ,
    SET_MINI_PLAYER,
    SET_IS_PLAYING,
    SET_MODE_TYPE,
    SET_LIST_PLAYER,
    SET_SONG_DETAIL,
    SET_SONG_LYRIC,
    SET_DEL_SONG,
    SET_CURRENT_INDEX,
    SET_CURRENT_TIME,
    SET_FAVORITE_SONG,
    SET_FAVORITE_LIST,
    SET_HISTORY_SONG,
    SET_HISTORY_LIST
 } from './mutations-type';
export default{
    // changeFullScreen(state,flag){
    //     state.isFullScreen =flag;
    //   }
    //加上[] 把常量变为方法使用
    [SET_FULL_SCREEN](state,flag){
        state.isFullScreen =flag;
        if(flag){
          state.isShowMiniPlyaer =false;
          state.isShowListPlayer =false;
        }
    },
    //修改迷你播放器
    [SET_MINI_PLAYER](state,flag){
        state.isShowMiniPlyaer =flag;
        if(flag){
            state.isFullScreen =false;
            state.isShowListPlayer =false;
        }
    },
    //修改播放按钮
    [SET_IS_PLAYING](state,flag){
        state.isPlaying =flag;
    },
    //修改播放模式
    [SET_MODE_TYPE](state,flag){
        state.modeType =flag;
    },
    //mini播放器-播放列表
    [SET_LIST_PLAYER](state,flag){
        state.isShowListPlayer =flag;
    },
    //可播放歌曲列表
    [SET_SONG_DETAIL](state,list){
        state.songs =list;
    },
    //修改当前播放歌曲歌词
    [SET_SONG_LYRIC](state,lyric){
        state.currentLyric =lyric;
    },
    //删除播放列表歌曲
    [SET_DEL_SONG](state,index){
        if(index != undefined){
            state.songs.splice(index,1)
        }else{
            state.songs=[];
        }
        if(index<state.currentIndex){
            state.currentIndex = state.currentIndex-1
        }
        if(state.songs.length === 0){
            state.isFullScreen =false;
            state.isShowMiniPlyaer =false;
            state.isShowListPlayer =false;
        }
    },
    //修改当前播放歌曲索引
    [SET_CURRENT_INDEX](state,index){
        if(index < 0){
            index = state.songs.length -1
        }else if(index > state.songs.length -1){
            index = 0
        }
        state.currentIndex =index;
    },
    //修改当前播放歌曲进度
    [SET_CURRENT_TIME](state,time){
        state.curTime =time;
    },
    //添加收藏歌曲
    [SET_FAVORITE_SONG](state,song){
        let result = state.favoriteList.find(function(currentValue){
            return currentValue === song
        })
        if(result === undefined){
            state.favoriteList.push(song);
        }
    },
    //重置收藏歌曲列表
    [SET_FAVORITE_LIST](state,list){
        state.favoriteList =list;
    },
    //添加历史播放歌曲
    [SET_HISTORY_SONG]  (state, song) {
        let result = state.historyList.find(function (currentValue) {
          return currentValue.id === song.id
        })
        if (result === undefined) {
          if (state.historyList.length > 30) {
            state.historyList.splice(0, 1)
          }
          state.historyList.push(song)
        }
      },
      //重置播放历史
      [SET_HISTORY_LIST] (state, list) {
        state.historyList = list
      }
}